package com.aqie.easy.hash;

import java.util.ArrayList;

/**
 * 202 快乐数
 */
public class IsHappy {
    public static boolean isHappy(int n) {
        ArrayList<Integer> list = new ArrayList<>();
        int square = n;


        while (square != 1){
            square = getSquare(square);
            if (list.contains(square)) return false;
            list.add(square);
        }
        return true;
    }

    private static int getSquare(int num) {
        int square = 0;
        while(num > 0){
            int y = num % 10;
            System.out.println(y);
            num /= 10;
            square += y * y;
        }
        return square;
    }

    public static void main(String[] args) {
        int num = 19;
        int square = getSquare(num);
        // System.out.println(square);
        System.out.println(isHappy(1));

    }
}
